package com.yanqu.road.server.cmd.vehiclesoul;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.vehicle.VehicleProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.vehicle.VehicleSoulModule;
import com.yanqu.road.server.protocol.Protocol;
import java.util.List;


@Cmd(code = Protocol.S_VSOUL_COMPOSE, desc = "魂石合成")
public class VehicleComposeSoulCmd extends AbstractCommand {

	private List<Integer> soulIdList;
	private int lockType;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		VehicleProto.VehicleSoulComposeReqMsg reqMsg = VehicleProto.VehicleSoulComposeReqMsg.parseFrom(packet.getBytes());
		soulIdList = reqMsg.getSoulIdList();
		lockType = reqMsg.getLockType();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ret = player.getModule(VehicleSoulModule.class).composeSoul(soulIdList,lockType);
	}

	@Override
	public void sendData(GamePlayer player) {
		if(ret != 0){
			VehicleProto.VehicleSoulComposeRespMsg.Builder respMsg = VehicleProto.VehicleSoulComposeRespMsg.newBuilder();
			respMsg.setRet(ret);
			player.sendPacket(Protocol.U_VSOUL_COMPOSE, respMsg);
		}
	}

}
